import { onLoad } from '@dcloudio/uni-app'
import { hideLoading, showLoading } from '@/util/uniapp'
import { ref } from 'vue'

export default function useOnLoadData (api, params,defaultValue, notLoading) {
  const data = ref(defaultValue)

  onLoad(() => {
    getData()
    if (!notLoading) {
      showLoading({})
    }
  })
  const getData = async () => {
    const { data: responseData } = await api(params)
    data.value = responseData
    hideLoading()
  }

  return {
    data,
  }
}
